package cn.edu.qlnu.xky.test.model;

/**
 * @author : wuweihong
 * @desc : TODO  请填写你的功能描述
 * @date : 2025-06-20
 */


import java.util.Date;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * 借阅记录实体类
 */
public class Borrow {

	private Integer id;            // 主键ID
	private Integer userId;        // 读者ID
	private Integer bookId;        // 书籍ID
	private Date borrowDate;       // 借阅日期
	private Date dueDate;          // 应还日期
	private Date returnDate;       // 实际归还日期
	private Integer isReturn;      // 是否归还: 0-未还, 1-已还
	private Integer isExceed;      // 是否超期: 0-未超期, 1-已超期
	private Integer fine;          // 罚款金额（单位：角）

	private String userName;

	private String bookName;

	private int overDueDays;

	// Getter 和 Setter 方法

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Integer getBookId() {
		return bookId;
	}

	public void setBookId(Integer bookId) {
		this.bookId = bookId;
	}

	public Date getBorrowDate() {
		return borrowDate;
	}

	public void setBorrowDate(Date borrowDate) {
		this.borrowDate = borrowDate;
	}

	public Date getDueDate() {
		return dueDate;
	}

	public void setDueDate(Date dueDate) {
		this.dueDate = dueDate;
	}

	public Date getReturnDate() {
		return returnDate;
	}

	public void setReturnDate(Date returnDate) {
		this.returnDate = returnDate;
	}

	public Integer getIsReturn() {
		return isReturn;
	}

	public void setIsReturn(Integer isReturn) {
		this.isReturn = isReturn;
	}

	public Integer getIsExceed() {
		return isExceed;
	}

	public void setIsExceed(Integer isExceed) {
		this.isExceed = isExceed;
	}

	public Integer getFine() {
		return fine;
	}

	public void setFine(Integer fine) {
		this.fine = fine;
	}

	public void setOverDueDays() {
		Date now = new Date();
		if (Objects.nonNull(this.dueDate)) {
			long diffInMillis = Math.abs(now.getTime() - this.dueDate.getTime());
			int interval = Math.toIntExact(TimeUnit.DAYS.convert(diffInMillis, TimeUnit.MILLISECONDS));
			this.overDueDays = interval;
		}
	}

	public int getOverDueDays() {
		return overDueDays;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getBookName() {
		return bookName;
	}

	public void setBookName(String bookName) {
		this.bookName = bookName;
	}
}

